﻿// final step in a single block: http://en.wikipedia.org/wiki/Adler-32

#include <iostream>
#include <fstream>
using namespace std;

#include "Adler32.h"

int main()
{
	const int BUFLEN = 1024;	// 1kiB
	unsigned char buffer[BUFLEN];
	ifstream fin("txt.txt", ios_base::in | ios_base::binary);
	if(!fin.is_open()) { cerr << "error" << endl; return 0; }
	//
	streamsize read;
	while(1)
	{
		// compute checksum of a single block
		fin.read((char *)buffer, BUFLEN);
		if((read = fin.gcount()) > 0)
			cout << "0x" << hex << Adler32::Compute(buffer, read) << endl;	// Wikipedia --> 0x11E60398
		if(fin.eof()) break;
	}
	//
	fin.close();
	cout << "Ok." << endl;
	return 0;
}